package com.yunji.ylexpiration_backstage.controller;

import com.yunji.ylexpiration_backstage.entity.FurnCommodity;
import com.yunji.ylexpiration_backstage.service.FurnCommodityService;
import com.yunji.ylexpiration_backstage.service.FurnVarietysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class FurnCommodityController {
    @Autowired
    private FurnCommodityService furnCommodityService;

    @Autowired
    private FurnVarietysService furnVarietysService;

    @RequestMapping("product-list.html")
    public String productlist(Model model,String productname){
        if(productname==null){
            productname="";
        }
        List<FurnCommodity> all = furnCommodityService.getAll(productname);
        model.addAttribute("all",all);
        return "product-list.html";
    }

    @GetMapping("deleteProduct.html")
    @ResponseBody
    public int delteProduct(Integer [] id){
        int deletebatchesccolor = furnVarietysService.deletebatchesccolor(id);
        int deletebatches = furnCommodityService.deletebatches(id);
        if(deletebatches>0&&deletebatchesccolor>0){
            return 1;
        }
        return 0;

    }
}
